<template>
  <div style="margin-bottom: 20px;">
    <el-dialog
      width="500px" :title="edit_main_title" append-to-body v-dialogDrag :visible.sync="edit_flag"
      @open="handleOpenConfig" :before-close="handleClose">
      <el-form ref="sendMsgRef" :rules="rules" label-width="130px" style="margin: 6px 0 0 0" :model="sendMsgData">
        <!--#vin#-->
        <el-form-item prop="vin" label="车架号">
          <el-input type="textarea" v-model="sendMsgData.vin"  placeholder="请输入车架号" style="width: 220px"></el-input>
        </el-form-item>
      </el-form>
      <el-row type="flex" justify="end">
        <el-button type="primary" @click="handleClose">取消</el-button>
        <el-button type="primary" @click="confirmClick">确认</el-button>
      </el-row>
    </el-dialog>
  </div>
</template>

<script type="text/javascript">
  import * as certificateAPI from '@/api/certificate/certificate'
  export default {
    name: '',
    components: {
    },
    props: ['edit_flag', 'edit_main_title', 'edit_select_row', 'edit_params'],
    data() {
      return {
        sendMsgData: {
          vin: ''
        },
        rules: {
          vin: [
            { required: true, message: '请输入车架号', trigger: 'change' }
          ]
        }
      }
    },
    methods: {
      // 弹窗页打开初始
      handleOpenConfig() {
        this.sendMsgData.vin = ''
        const ids = []
        this.edit_select_row.map(item => {
          ids.push(item.vin)
        })
        this.sendMsgData.vin = ids.length > 1 ? ids.join(',') : ids[0]
      },
      confirmClick() {
        const that = this
        that.$refs['sendMsgRef'].validate(valid => {
          if (valid) {
            const toParams = {
              vin: that.sendMsgData.vin,
              handleType: that.$props.edit_params.handleType
            }
            certificateAPI.updateCertification(toParams).then(result => {
              that.$message({
                message: that.$props.edit_params.typeName + '成功',
                type: 'success',
                duration: 2000
              })
              that.$emit('edit-confirm', false)
            }).catch(() => {
            })
          }
        })
      },
      handleClose() {
        this.$emit('edit-close', false)
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
